package bairui.international.console.web.controller.prize.nine;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.querydsl.core.BooleanBuilder;

import bairui.international.model.domain.jpa.QTB_WinPrize;
import bairui.international.model.domain.jpa.TB_WinPrize;
import bairui.international.service.Service_WinPrize;

/**
 *
 * 详情
 *
 * @generated
 * 
 * @see STest_C_Prize_Nine_Detail_UserPage 测试
 *
 */
@Controller
public class C_Prize_Nine_Detail_UserPage
 extends SC_Prize_Nine_Detail_UserPage 
{
	
	@Autowired private Service_WinPrize service_WinPrize;
	
	/**
	 * 中奖用户
	 */
	@Action(UserPage.class)
	@GetMapping(value=UserPage.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object userPage(
		HttpServletRequest request, 
		@PathVariable(name=UserPage.PathVariableName.Id) long id
	) throws Exception {
		org.springframework.data.domain.Page<TB_WinPrize> page = service_WinPrize.page(
				it->filter(it, id, request), 
				UserPage.Output.page(request), 
				it->sort(it, request)
			);
		page.forEach(it->{
			it.setImgUrl(C_Prize_Nine_Detail_ShowItemImg.ShowItemImg.Operate(-1, it.getId()).getUrl());
		});
		//
		return UserPage.Output.output(
				page
			);
	}
	
	/*
	 * 过滤
	 */
	static BooleanBuilder filter(QTB_WinPrize it, long prizeId, HttpServletRequest request){
		return UserPage.Filter.query(it, request)
			.and(it.prize.id.eq(prizeId))
			.and(it.noPrizeFlag.eq(false));
	}
	
	/*
	 * 排序
	 */
	static Sort sort(QTB_WinPrize it, HttpServletRequest request){
		return UserPage.Output.sort(it, request, new UserPage.Output.OrderExtends(){
				@Override public Sort gainFinishor(Direction direction) {
					return sort(direction, it.finishor.name);
				}
			});
	}
	
	

}
